package com.fs.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.WhWarehousingMapper;
import com.fs.pojo.User;
import com.fs.pojo.WhWarehousing;
import com.fs.service.WhWarehousingService;
import com.fs.vo.Condition;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 入库单服务层实现类
 */

@Service
public class WhWarehousingServiceImpl implements WhWarehousingService {
    @Resource
    private WhWarehousingMapper whWarehousingMapper;


    /**
     * 根据id删除入库单
     *
     * @param warehousingEntryId
     */
    @Override
    public void deleteWh(int warehousingEntryId) {
        whWarehousingMapper.deleteById(warehousingEntryId);
    }

    /**
     * 新增入库单
     */
    @Override
    public void addWh(WhWarehousing whWarehousing) {
        whWarehousingMapper.insert(whWarehousing);
    }

    /**
     * 根据id修改入库单
     *
     * @param whWarehousing
     */
    @Override
    public void changeById(WhWarehousing whWarehousing) {
        whWarehousingMapper.updateById(whWarehousing);
    }

    /**
     * 根据id查询单个入库单
     *
     * @param warehousingEntryId
     * @return
     */
    @Override
    public WhWarehousing selectOneById(int warehousingEntryId) {
        return whWarehousingMapper.selectOneById(warehousingEntryId);
//        return whWarehousingMapper.selectById(warehousingEntryId);
    }

    /**
     * 查询所有入库单
     *
     * @return
     */
    @Override
    public List<WhWarehousing> selectAll() {
        return whWarehousingMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public PageInfo<WhWarehousing> selectPage(Condition<WhWarehousing> condition) {
        PageHelper.startPage(condition.getPage(), condition.getCount());
        List<WhWarehousing> whWarehousings = whWarehousingMapper.selectAll(condition.getSearch());
        return new PageInfo<>(whWarehousings);
    }
}
